package com.platform.modules.cpt.controller;

import java.util.Date;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.util.StringUtil;
import com.platform.common.utils.RestResponse;
import com.platform.modules.cpt.entity.CptAcceptanceSuperviseReportEntity;
import com.platform.modules.cpt.service.CptAcceptanceSuperviseReportService;
import com.platform.modules.quality.vo.CommonResult;
import com.platform.modules.sys.controller.AbstractController;
import com.platform.modules.sys.entity.SysUserEntity;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * Controller
 *
 * @author biaohuaming
 * @date 2020-02-24 15:28:20
 */
@Api(tags = "编写工程质量监督报告")
@RestController
@RequestMapping("cpt/acceptance/superviseReport")
public class CptAcceptanceSuperviseReportController extends AbstractController {


    @Autowired
    private CptAcceptanceSuperviseReportService cptAcceptanceSuperviseReportService;



    /**
     * @descr 查询<br>
     * @param id
     * @return
     */
    @ApiOperation(value = "查询")
    @GetMapping("/view")
    public RestResponse view(@RequestParam String cptAcceptanceId) {
    	Map<String, Object> params = getParams();
    	params.put("cptId", cptAcceptanceId);
    	CptAcceptanceSuperviseReportEntity entity = cptAcceptanceSuperviseReportService.queryOne(params);
        return RestResponse.success().put("data", entity);
    } 
    
    /**
     * @param cptAcceptanceSuperviseReportEntity
     * @return
     */
    @ApiOperation(value = "保存")
    @PostMapping("save")
    public CommonResult<CptAcceptanceSuperviseReportEntity> save(@RequestBody CptAcceptanceSuperviseReportEntity cptAcceptanceSuperviseReportEntity) {
    	SysUserEntity sysUserEntity = this.getUser();
    	if(StringUtil.isEmpty(cptAcceptanceSuperviseReportEntity.getId())) {
    		cptAcceptanceSuperviseReportEntity.setCreateTime(new Date());
    		cptAcceptanceSuperviseReportEntity.setCreateUser(sysUserEntity.getUserId());
    	}else {
    		cptAcceptanceSuperviseReportEntity.setUpdateTime(new Date());
    		cptAcceptanceSuperviseReportEntity.setUpdateUser(sysUserEntity.getUserId());
    	}
    	cptAcceptanceSuperviseReportService.saveOrUpdate(cptAcceptanceSuperviseReportEntity);
        return CommonResult.success(cptAcceptanceSuperviseReportEntity);
    }

}
